<template>
  <div>
    <div class="chatplat-text-container">
      <div v-for="(ele,index) in len" :key="index">
        <div class="chat-houduan" v-if="ele.kefu">
          <p>
            {{ ele.kefu }}
          </p>
        </div>
        <div class="chat-user"  v-if="ele.user">
          <p>
            {{ ele.user }}
          </p>
        </div>
      </div>
    </div>
    <div class="chatplat-container">
      <div class="chatplat-left">
        <i class="iconfont icon-yuyin"></i>
      </div>
      <div class="chatplat-middle">
        <input type="text" v-model="userText">
      </div>
      <div class="chatplat-right" @click="sendMsg">
        <i class="iconfont icon-jia"></i>
      </div>
    </div>
  </div>
  
</template>

<script>
  export default {
    name: 'chatPlat',
    data () {
      return {
        userText: '',
        kefuText: '',
        len: []
      }
    },
    methods: {
      sendMsg () {
        //发送消息
        var goEasy = new GoEasy({
          appkey: "BC-8861f5b3a1a748fb9e037e4776949537"
        });
        //GoEasy-OTP可以对appkey进行有效保护，详情请参考 7.GoEasy-OTP
        goEasy.publish({
          channel: "my_channel",
          message: this.userText,
          
        });
        let userObj = {
          user: this.userText
        }
        this.userText = ''
        this.len.push(userObj)
        //接收消息
        var goEasy = new GoEasy({
          appkey: "BC-8861f5b3a1a748fb9e037e4776949537"
        });
        goEasy.subscribe({
          channel: "your_channel",
          onMessage: function (message) {
            this.kefuText = message.content
            let kefuObj = {
              kefu: message.content
            }
            this.len.push(kefuObj)
          }.bind(this)
        });
      },
    }
  }
</script>

<style scoped>
.chatplat-text-container{
  width: 100%;
  position: absolute;
}
.chat-houduan,.chat-user{
  height: 0.9rem;
  line-height: 0.9rem;
  padding: 0.2rem;
  
}
.chat-houduan p,.chat-user p{
  display: inline-block;
  background-color: #13bf92;
  color: #fff;
  padding: 0 0.3rem;
  border-radius: 0.1rem;
}
.chat-houduan{
  left: 0.1rem;
  text-align: left;
}
.chat-user{
  right: 0.1rem;
  text-align: right;
}
.chatplat-container{
  height: 1rem;
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  background-color: #13bf92;
  display: flex;
}
.chatplat-left,.chatplat-right{
  width: 1rem;
  color: #fff;
 
  
}
.chatplat-left i{
  font-size: 0.6rem;
  font-weight: bold;
  
}
.chatplat-right i{
  font-size: 0.5rem;
 
}
.chatplat-left{
  margin-left: 0.2rem;
  margin-top: 0.17rem;
  text-align: center;
}
.chatplat-right{
  margin-left: 0.2rem;
  margin-top: 0.22rem;
}
.chatplat-middle{
  flex-grow: 1;
  
}
.chatplat-middle::before{
  content: '';
  display: block;
  width: 5rem;
  border-bottom: 1px solid #fff;
  position: relative;
  top: 0.75rem;
}
.chatplat-middle input{
  width: 5rem;
  height: 0.8rem;
  font-size: 0.3rem;
  padding-top: 0.1rem;
  padding-left: 0.05rem;
}


</style>